package bb.lanxing.lib.devices.bici.cmd;

//import com.umeng.analytics.pro.cc;
import bb.lanxing.lib.devices.bici.BLECommand;
import bb.lanxing.lib.devices.bici.BiciDate;
import bb.lanxing.lib.devices.utils.ByteUtils;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Map;

public class SettingCMD extends BLECommand implements Serializable {
    public static final byte COMMAND_ID = 7;
    public static final byte KEY_ALARM = 5;
    public static final byte KEY_AUTO_LOCK = 6;
    public static final byte KEY_BICI_AUTO_POWER = 15;
    public static final byte KEY_BICI_BIKE_NUMBER = 13;
    public static final byte KEY_BICI_COLOR = 12;
    public static final byte KEY_BICI_INTIAL_PASSCORD = 14;
    public static final byte KEY_BICI_MODE = 11;
    public static final byte KEY_LIGHT_HEAD = 2;
    public static final byte KEY_LIGHT_WIDTH = 3;
    public static final byte KEY_MSG_PHONENUMBER = 9;
    public static final byte KEY_NAME = 1;
    public static final byte KEY_PHONE_NOTIFY = 7;
    public static final byte KEY_TIME = 4;
    public static final byte KEY_USER_PROFILE = 8;
    public static final short USER_PROFILE_LEN = 8;
    private byte age;
    private byte alarm;
    private byte autoLock;
    private byte autoPower;
    private String bikeName;
    private byte gender;
    private byte height;
    private byte lightHead;
    private byte lightWidth;
    private byte phoneNotify;
    private String phoneNumber;
    private long time;
    private byte[] userProfile;
    private short weight;

    public SettingCMD() {
        this.commandId = (byte) 7;
    }

    public SettingCMD(byte[] bArr) {
        super(bArr);
    }

    @Override
    public void parseBody(byte[] bArr) {
        if (bArr.length < 3) {
            return;
        }
        ByteBuffer wrap = ByteBuffer.wrap(bArr);
        byte b = wrap.get();
        int i = wrap.getShort();
        byte[] bArr2 = new byte[(bArr.length - i) - 3];
        if (b != 15) {
            switch (b) {
                case 1:
                    byte[] bArr3 = new byte[i];
                    wrap.get(bArr3);
                    this.bikeName = new String(bArr3);
                    break;
                case 2:
                    this.lightHead = wrap.get();
                    break;
                case 3:
                    this.lightWidth = wrap.get();
                    break;
                case 4:
                    this.time = BiciDate.biciDateToTimestamp(wrap.getInt());
                    break;
                case 5:
                    this.alarm = wrap.get();
                    break;
                case 6:
                    this.autoLock = wrap.get();
                    break;
                case 7:
                    this.phoneNotify = wrap.get();
                    break;
                case 8:
                    byte[] bArr4 = new byte[i];
                    this.userProfile = bArr4;
                    wrap.get(bArr4);
                    parseUserProfile();
                    break;
                case 9:
                    byte[] bArr5 = new byte[i];
                    wrap.get(bArr5);
                    this.phoneNumber = new String(bArr5);
                    break;
            }
        } else {
            this.autoPower = wrap.get();
        }
        wrap.get(bArr2);
        parseBody(bArr2);
    }

    private void parseUserProfile() {
        ByteBuffer wrap = ByteBuffer.wrap(this.userProfile);
        this.gender = wrap.get(3);
        this.height = wrap.get(4);
        this.weight = wrap.getShort(5);
        this.age = wrap.get(7);
    }

    public String toString() {
        return "name = " + this.bikeName + "\n lightHead = " + ((int) this.lightHead) + "\n lightWidth = " + ((int) this.lightWidth) + "\n time = " + this.time + "\n alarm = " + ((int) this.alarm) + "\n autoLock = " + ((int) this.autoLock) + "\n phoneNotify = " + ((int) this.phoneNotify) + "\n userProfile = " + ByteUtils.printlnByteArrayToUnsignHexString(this.userProfile) + "\n gender = " + ((int) this.gender) + "\n height = " + ((int) this.height) + "\n weight = " + ((int) this.weight) + "\n age = " + ((int) this.age) + "\n phoneNumber = " + this.phoneNumber + "\n autoPower = " + ((int) this.autoPower);
    }

    @Override
    protected byte[] encodeCMDBody(Map<Byte, Object> map) {
        int i;
        ByteBuffer allocate = ByteBuffer.allocate(500);
        allocate.put((byte) 7);
        allocate.put((byte) 16);//cc.n
        if (map.get((byte) 1) != null) {
            allocate.put((byte) 1);
            String str = (String) map.get((byte) 1);
            allocate.putShort((short) str.getBytes().length);
            allocate.put(str.getBytes());
            i = str.getBytes().length + 5;
        } else {
            i = 2;
        }
        if (map.get((byte) 2) != null) {
            allocate.put((byte) 2);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 2));
            i += 4;
        }
        if (map.get((byte) 3) != null) {
            allocate.put((byte) 3);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 3));
            i += 4;
        }
        if (map.get((byte) 4) != null) {
            allocate.put((byte) 4);
            allocate.putShort((short) 4);
            allocate.putInt(BiciDate.timestampToBiciDate((Long) map.get((byte) 4)));
            i += 7;
        }
        if (map.get((byte) 5) != null) {
            allocate.put((byte) 5);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 5));
            i += 4;
        }
        if (map.get((byte) 6) != null) {
            allocate.put((byte) 6);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 6));
            i += 4;
        }
        if (map.get((byte) 7) != null) {
            allocate.put((byte) 7);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 7));
            i += 4;
        }
        if (map.get((byte) 8) != null) {
            allocate.put((byte) 8);
            allocate.putShort((short) 8);
            allocate.put((byte[]) map.get((byte) 8));
            i = i + 3 + 8;
        }
        if (map.get((byte) 9) != null) {
            allocate.put((byte) 9);
            String str2 = (String) map.get((byte) 9);
            allocate.putShort((short) str2.length());
            allocate.put(str2.getBytes());
            i = i + 3 + str2.length();
        }
        if (map.get((byte) 11) != null) {
            allocate.put((byte) 11);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 11));
            i += 4;
        }
        if (map.get((byte) 12) != null) {
            allocate.put((byte) 12);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 12));
            i += 4;
        }
        if (map.get((byte) 13) != null) {
            allocate.put((byte) 13);
            int intValue = (Integer) map.get((byte) 13);
            allocate.putShort((short) 4);
            allocate.putInt(intValue);
            i += 7;
        }
        if (map.get((byte) 15) != null) {
            allocate.put((byte) 15);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 15));
            i += 4;
        }
        byte[] bArr = new byte[i];
        allocate.flip();
        allocate.get(bArr);
        return bArr;
    }

    public String getBikeName() {
        return this.bikeName;
    }
}
